<template>
  <div class="school">
    <h2>学校名称： {{ name }}</h2>
    <h2>学校地址: {{ address }}</h2>
  </div>
</template>

<script>
// 消息订阅
import pubsub from 'pubsub-js'
export default {
  name: "Student",
  data() {
    return {
      name: "天津123456",
      address: "西青",
    };
  },
  mounted() {
   this.pubId = pubsub.subscribe('hello', (msgName,data) => {
     console.log(this);
      console.log('有人发布了hello消息,hello消息的回调执行了', msgName,data);
    })
  },

  beforeDestroy() {
    pubsub.unsubscribe(this.pubId)
  }
 
};
</script>

<style scoped>
.school {
  background: rgb(185, 150, 150);
}
</style>